package cn.lanqiao.ui;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import cn.lanqiao.service.WordService;
import cn.lanqiao.service.impl.WordServiceImpl;

public class DeleteFrm extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField accountField;
	private JPasswordField passwordField;
	private JLabel label_2;
	private JLabel label_3;
	private JLabel label_4;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					DeleteFrm frame = new DeleteFrm();
					frame.setLocationRelativeTo(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public DeleteFrm() {
		setIconImage(Toolkit.getDefaultToolkit().getImage("photoes\\tubiao.png"));
		setResizable(false);
		setTitle("注销");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 465, 289);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("账号：");
		label.setForeground(new Color(255, 255, 255));
		label.setFont(new Font("黑体", Font.PLAIN, 14));
		label.setBounds(23, 80, 48, 25);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("密码：");
		label_1.setForeground(new Color(255, 255, 255));
		label_1.setFont(new Font("黑体", Font.PLAIN, 14));
		label_1.setBounds(23, 143, 48, 25);
		contentPane.add(label_1);
		
		accountField = new JTextField();
		accountField.setBounds(100, 82, 194, 21);
		contentPane.add(accountField);
		accountField.setColumns(10);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(100, 145, 194, 21);
		contentPane.add(passwordField);
		
		JButton button = new JButton("");
		button.setIcon(new ImageIcon("photoes\\zhuxiao.png"));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String uaccount = accountField.getText();
				String upassword = new String(passwordField.getPassword());
				cn.lanqiao.service.UserLoginService service = new cn.lanqiao.service.impl.UserLoginServiceImpl();
				int affter = service.check(uaccount, upassword);
				if(affter!=0) {
					UserLoginFrm ulf = new UserLoginFrm();
					ulf.deleteRemP();
					WordService ws = new WordServiceImpl();
					ws.deleteWord(uaccount);
					JOptionPane.showMessageDialog(null, "注销成功");
					System.exit(0);
				}else {
					JOptionPane.showMessageDialog(null, "信息有误，请检查后重新输入", "注销失败", JOptionPane.YES_OPTION);
				}
			}
		});
		button.setFont(new Font("宋体", Font.PLAIN, 14));
		button.setBounds(100, 198, 194, 36);
		contentPane.add(button);
		
		label_4 = new JLabel("呜呜主人你不要我了吗？");
		label_4.setForeground(new Color(127, 255, 212));
		label_4.setFont(new Font("华文行楷", Font.PLAIN, 20));
		label_4.setBounds(10, 23, 227, 36);
		contentPane.add(label_4);
		
		JButton button_1 = new JButton("取消");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DeleteFrm.this.dispose();
			}
		});
		button_1.setForeground(new Color(255, 255, 255));
		button_1.setBackground(new Color(255, 0, 0));
		button_1.setFont(new Font("黑体", Font.PLAIN, 17));
		button_1.setBounds(334, 211, 93, 23);
		contentPane.add(button_1);
		
		label_3 = new JLabel("");
		label_3.setIcon(new ImageIcon("photoes\\xiaogou.png"));
		label_3.setBounds(304, 58, 143, 150);
		contentPane.add(label_3);
		
		label_2 = new JLabel("");
		label_2.setFont(new Font("方正姚体", Font.PLAIN, 12));
		label_2.setIcon(new ImageIcon("photoes\\riluo.png"));
		label_2.setBounds(0, 0, 460, 260);
		contentPane.add(label_2);
	}
}
